package com.example.es.myapplication;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.es.myapplication.BaseFragment;
import com.example.zqm.neu612.Adapter.CollectAdapter;
import com.example.zqm.neu612.JavaBean.CollectionBean;
import com.example.zqm.neu612.Model.UserModel;
import com.example.zqm.neu612.R;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class CollectFoodFragment extends BaseFragment {
    public Context context;
    private RecyclerView recyclerView;
    private View view = null;

    public CollectFoodFragment(){
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view = inflater.inflate(R.layout.fragment_container,container,false);
        recyclerView = (RecyclerView) view.findViewById(R.id.collect_rv);


        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));//设置布局

        return view;
    }
    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    public void initData(){
        UserModel userModel = new UserModel();
        Call call = userModel.getAllUserCollection1(getUser_id(),"1");
        Callback<List<CollectionBean>> callback = new Callback<List<CollectionBean>>() {
            @Override
            public void onResponse(Call<List<CollectionBean>> call, Response<List<CollectionBean>> response) {
                List<CollectionBean> collectionBeen = response.body();
                recyclerView.setAdapter(new CollectAdapter(getActivity(),collectionBeen));
            }

            @Override
            public void onFailure(Call<List<CollectionBean>> call, Throwable t) {
                System.out.println("请求失败！");
                Log.i("onFailure","onFailure="+t.getMessage());
            }
        };
        call.enqueue(callback);
    }

}
